package cn.com.haopy.yue.ai.db.service.hos.impl;

import cn.com.haopy.yue.ai.db.entity.arisk.AIRiskCheckIndex;
import cn.com.haopy.yue.ai.db.mapper.arisk.AIRiskCheckIndexMapper;
import cn.com.haopy.yue.ai.db.service.BaseServiceImpl;
import cn.com.haopy.yue.ai.db.service.hos.AIRiskCheckIndexService;
import cn.com.haopy.yue.ai.db.utils.SqlInjectionExtUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @Description: TODO
 * @Author DuTao
 * @Date 2025/3/27 11:31
 */
@Service
public class AIRiskCheckIndexServiceImpl extends BaseServiceImpl<AIRiskCheckIndexMapper, AIRiskCheckIndex>
        implements AIRiskCheckIndexService {

    @Override
    public Page<AIRiskCheckIndex> querySelective(String resultType, String checkIndexName, Integer page, Integer limit, String sort, String order) {
        if (SqlInjectionExtUtils.check(sort) || SqlInjectionExtUtils.check(order)) {
            throw new RuntimeException("存在非法字段");
        }
        QueryWrapper<AIRiskCheckIndex> queryWrapper = new QueryWrapper<>();
        if (StringUtils.hasText(resultType)) {
            queryWrapper.lambda().eq(AIRiskCheckIndex::getResultType, resultType);
        }
        if (StringUtils.hasText(checkIndexName)) {
            queryWrapper.lambda().like(AIRiskCheckIndex::getCheckIndexName, checkIndexName);
        }
        if (StringUtils.hasText(sort) && StringUtils.hasText(order)) {
            queryWrapper.orderBy(true, "asc".equals(order), sort);
        }
        return super.page(new Page<>(page, limit), queryWrapper);
    }

    @Override
    public List<AIRiskCheckIndex> getByName(String checkIndexName) {
        QueryWrapper<AIRiskCheckIndex> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(AIRiskCheckIndex::getCheckIndexName, checkIndexName);
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public List<AIRiskCheckIndex> getAll() {
        return super.list();
    }

    @Override
    public List<AIRiskCheckIndex> getJudgeNormalList() {
        QueryWrapper<AIRiskCheckIndex> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(AIRiskCheckIndex::getIsJudgeIllness, Boolean.FALSE);
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public List<AIRiskCheckIndex> getJudgeIllnessList() {
        QueryWrapper<AIRiskCheckIndex> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(AIRiskCheckIndex::getIsJudgeIllness, Boolean.TRUE);
        return baseMapper.selectList(queryWrapper);
    }
}
